package chapter_eleven.p152;

import java.util.ArrayList;

/**
 * Data time:2021/10/18 15:14
 * StudentID:2019112118
 * Author:hgw
 * Description: 文件夹类，充当容器构建类
 */
public class Folder extends AbstractFile{

    //定义集合fileList,用于存储AbstractFile类型的成员
    private ArrayList<AbstractFile> fileList = new ArrayList<AbstractFile>();
    private String name;

    public Folder(String name) {
        this.name = name;
    }

    public void add(AbstractFile file) {
        fileList.add(file);
    }

    public void remove(AbstractFile file) {
        fileList.remove(file);
    }

    public AbstractFile getChild(int i) {
        return (AbstractFile)fileList.get(i);
    }

    public void killVirus() {
        System.out.println("****对文件夹'" + name + "'进行杀毒");   //模拟杀毒

        //递归调用成员构建的killVirus()方法
        for (AbstractFile abstractFile : fileList) {
            abstractFile.killVirus();
        }
    }
}
